$(() => {
    let $get = $("#get");
    let $inputbox = $("#inputbox");
    $inputbox.focus();
    let $main = $("#main");
    let $table = $("#table");
    let $item1 = $("#item1");
    let $item2 = $("#item2");
    let $item3 = $("#item3");
    let $item4 = $("#item4");
    let $item5 = $("#item5");
    let $item6 = $("#item6");
    let $item7 = $("#item7");
    let $select1 = $("#select1");
    let $select2 = $("#select2");
    let data, pchilds, cchilds;
    $inputbox.keydown(e => { if (e.keyCode === 13) $get.click(); });
    $(document).keydown(e => { if (e.keyCode === 36) { if (e.ctrlKey) { if (confirm("是否要返回上一页？")) { location.href = "./?/index"; } } else { if (confirm("是否要返回首页？")) { history.back(); } } } else if (e.keyCode === 45) { $inputbox.focus(); } });
    $.post("{LINK_address}", {}, text => {
        $main.removeClass("el-loading");
        $table.hide();
        $table.removeClass("el-loading");
        data = JSON.parse(text);
        if (data.code == 1) {
            let x = `<option value="">--选择省--</option>`;
            for (let i = 0; i < data.data.length; i++) {
                x += `<option value="${i}">${data.data[i].name}</option>`;
            }
            $select1.html(x);
            $select1.removeAttr("disabled");
        } else {
            alert(data.msg);
        }
        /* console.log(text); */
    });
    $select1.change(() => {
        let a = $select1.val();
        pchilds = data.data[a].pchilds;
        let x = `<option value="">--选择市--</option>`;
        for (let i = 0; i < pchilds.length; i++) {
            x += `<option value="${i}">${pchilds[i].name}</option>`
        }
        $select2.html(x);
        $select2.removeAttr("disabled");
    });
    $get.click(() => {
        $main.addClass("el-loading");
        let province = data.data[$select1.val()].name;
        let city = pchilds[$select2.val()].name;
        $.post("#", {
            province: province,
            city: city
        }, text => {
            $main.removeClass("el-loading");
            $table.hide();
            $table.removeClass("el-loading");
            // console.log(text);
            // return;
            let data = JSON.parse(text);
            $item1.text(data.confirmedCount);
            $item2.text(data.curedCount);
            $item3.text(data.currentConfirmedCount);
            $item4.text(data.deadCount);
            $item5.text(data.highDangerCount);
            $item6.text(data.midDangerCount);
            $item7.text(data.suspectedCount);
            $table.fadeIn();
            console.log(data);
            /* console.log(text); */
        });
    });
});